package com.wn.icloud.auth.client.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by leeyang on 2017/9/15.
 */
@ConfigurationProperties("auth.client")
@Configuration
public class ServiceAuthConfig {

    private byte[] pubKeyByte;
    private String id;
    private String secret;
    private String tokenHeader;
    private String applicationName;

    private List<String> includeUrlPatter = new ArrayList<>();

    private List<String> excludeUrlPatter = new ArrayList<>();

    public String getTokenHeader() {
        return tokenHeader;
    }

    public void setTokenHeader(String tokenHeader) {
        this.tokenHeader = tokenHeader;
    }

    public String getClientId() {
        return "null".equals(id) ? applicationName : id;
    }

    public void setClientId(String clientId) {
        this.id = clientId;
    }

    public String getClientSecret() {
        return this.secret;
    }

    public void setClientSecret(String clientSecret) {
        this.secret = clientSecret;
    }

    public String getToken(HttpServletRequest request) {
        return request.getHeader(this.getTokenHeader());
    }

    public byte[] getPubKeyByte() {
        return pubKeyByte;
    }

    public void setPubKeyByte(byte[] pubKeyByte) {
        this.pubKeyByte = pubKeyByte;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public List<String> getIncludeUrlPatter() {
        return includeUrlPatter;
    }

    public void setIncludeUrlPatter(List<String> includeUrlPatter) {
        this.includeUrlPatter = includeUrlPatter;
    }

    public List<String> getExcludeUrlPatter() {
        return excludeUrlPatter;
    }

    public void setExcludeUrlPatter(List<String> excludeUrlPatter) {
        this.excludeUrlPatter = excludeUrlPatter;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }
}
